<template>
  <div class="app-container">
    <div class="zd3">
      <div class="zd3-title">
        <p>
          <span>课程名</span>
          <input v-model="searchData.name" type="text" placeholder="请输入课程名" />
        </p>
        <el-button size="small" type="success" @click="getlist">查询</el-button>
        <el-button size="small" @click="resetList">重置</el-button>
        <el-button size="small" type="primary" @click="addHanlder">新增</el-button>
      </div>
      <div class="zd3-btm">
        <el-table
          :data="tableData"
          style="width: 100%;border-radius: 8px;"
          :show-header="showHeader"
          v-loading="loading"
        >
          <el-table-column align="center" prop="title" label="课程名称" />
          <el-table-column align="center" prop="description" label="课程简介" >
            <template slot-scope="scope">
              <p v-html="scope.row.description"></p>
            </template>
          </el-table-column>
          <el-table-column align="center" prop="cover" label="封面图片" >
            <template slot-scope="scope">
              <img :src="scope.row.cover" alt="" class="avatars">
            </template>
          </el-table-column>
          <el-table-column align="center" prop="teacherId" label="讲师" />
          <el-table-column align="center" width="220" label="操作">
            <template slot-scope="scope">
              <el-button type="text" size="small" @click="write(scope.row)">修改</el-button>
              <el-popconfirm
                placement="top"
                hideIcon
                title="是否要删除此行？"
                @onConfirm="deleteRow(scope.row)"
              >
                <el-button type="text" size="small" slot="reference">删除</el-button>
              </el-popconfirm>
              <el-button type="text" size="small" @click="zhangjie(scope.row,scope.$index)">章节管理</el-button>
              <el-button type="text" size="small" @click="ceshiti(scope.row,scope.$index)">测试题管理</el-button>
            </template>
          </el-table-column>
        </el-table>
        <el-pagination
          background
					align="right"
					:page-size="50"
          layout="prev, pager, next"
          :total="total"
					@current-change='goPage'
          @prev-click="goPrev"
          @next-click="goNext"
        />
      </div>
    </div>
  </div>
</template>

<script>
let temp = null;
 import {selectMiaoshu,addKecheng,updateKecheng,deleteKecheng,allTeacherList,uploadFile } from '@/api/people'
  export default {
    data(){
      return{
        total: 1,            //总页数
        page: 1,             //当前页数
        showHeader: true,    //是否显示表头
        loading: true,       //表格数据加载
        tableData: [],       //表格数据
        teacherData: [],      //讲师列表
        tempData: {},        //中介数据
        searchData: {},       //搜索数据
        boxshow: false,        //弹窗
        tempIndex: -1,
        
      }
    },
    mounted(){
      console.log(this.$route.params)
      temp = JSON.parse(localStorage.getItem('ids'))
      this.getlist()
    },
    methods:{
      // 获取课程列表
      getlist(){
        this.searchData.currentPage  = this.page
        console.log('课程列表加载')
        selectMiaoshu(temp.twoId).then(res => {
          console.log(res)
          if(res.data){
            this.tableData = res.data.item
            console.log(this.tableData)
            this.loading = false
          }else{
            this.loading = false
          }
        }).catch(res => {
          console.log(res)
          this.loading = false
        })
      },
      zhangjie(item){
        this.$router.push({
          name: 'Zhangjieguanli',
          params: {
            options: JSON.stringify(item)
          }
        })
      },
      ceshiti(item){
        this.$router.push({
          name: 'Problemtest',
          params: {
            options: JSON.stringify(item)
          }
        })
      },
      // 新增res
      addHanlder(item){
        this.$router.push({
          name: 'Writekecheng',
          params: {
            father: JSON.stringify(temp)
          }
        })
      },
      resetList(){
        this.searchData = {}
      },
      // 修改
      write(res){
        console.log(res)
        this.$router.push({
          name: 'Writekecheng',
          params: {
            father: JSON.stringify(temp),
            options: JSON.stringify(res)
          }
        })
        this.boxshow = true
        this.tempIndex = index
        this.tempData = {...res}
      },
      // 删除
      deleteRow(res){
        console.log(res)
        deleteKecheng(res.id).then(res => {
          console.log(res)
          this.$message({
            message: res.message,
            type: 'success'
          })
          this.getlist()
        })
      },
      // 上一页
      goPrev(page) {
        console.log(page);
        this.page--
        this.getlist()
      },
      // 下一页
      goNext(page) {
        console.log(page);
        this.page++
        this.getlist()
      },
      // 跳转指定页
      goPage(page){
        this.page = page
        this.getlist()
      },
    }
  }
</script>

<style scoped lang="scss">
/deep/.el-button--primary {
  color: #fff;
  background-color: #18a05e !important;
  border-color: #18a05e !important;
  border: none
}
.avatar-uploader .el-upload {
  border: 1px dashed #999 !important;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  width: 100%;
}
.avatar-uploader .el-upload:hover {
  border-color: #409eff;
}
.avatars{
	width: 45px;
	height: 45px;
  margin: 0 auto;
  border: 1px solid #ccc
}

.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 100px;
  height: 100px;
	border: 1px dashed #CCCCCC;
  line-height: 100px;
  text-align: center;
}
.avatar {
  width: 100px;
  height: 100px;
  display: block;
}
.upload-demo{
  margin: 0 10px;
}
/deep/.el-button--primary:hover,
.el-button--primary:focus {
  background: #18a05e !important;
  border-color: #18a05e !important;
  color: #fff !important;
}
/deep/.el-button--primary {
  color: #fff;
  background-color: #18a05e;
  border-color: #18a05e;
}
/deep/.el-button--text {
  color: #00c666 !important;
}
/deep/.el-pagination.is-background .el-pager li:not(.disabled).active {
  background-color: #18a05e;
  color: #fff;
}
.zd3-btm /deep/.btn-prev:after {
  content: "上一页";
}
.zd3-btm /deep/.btn-next:before {
  content: "下一页";
}
.zd3-btm /deep/.btn-prev,
.zd3-btm /deep/.btn-next {
  width: 65px;
	display: inline-flex;
	align-items: center;
	justify-content: center;
}
.app-container {
  padding: 10px;
}
.ellisp{
	width: 100%;
	display: -webkit-box;
	-webkit-box-orient: vertical;
	-webkit-line-clamp: 3;
	overflow: hidden;
	text-align: left;
}
.rolestip {
  width: 100%;
  display: flex;
  justify-content: center;
}
.inps {
  width: 100%;
  height: 32px;
  line-height: 32px;
  padding-left: 10px;
  background: none;
  border: none;
  color: #333;
}
.inps-active {
  width: 100%;
  height: 32px;
  line-height: 32px;
  padding-left: 10px;
  // background:#ccc;
  border: none;
  color: #333;
}
.s-img{
  width: 80px;
  height: 80px;
}
.zd3-title {
	// height: 80px;
	display: flex;
  flex-wrap: wrap;
	align-items: center;
	padding: 20px;
	position: relative;
	background: #ffffff;
	border-radius: 8px;
	border: 1px solid rgba(0, 0, 0, 0.1);

	> p {
		font-size: 14px;
    display: flex;
    color: #333;
    align-items: center;
    margin: 10px 30px 10px 0;
		> span {
			padding-right: 20px;
      width: 80px;
		}

		> input {
			width: 200px;
			height: 32px;
			// background: #ccc;
			border-radius: 3px;
			border: 1px solid #ccc;
			padding-left: 10px;
			color: #333;
		}
	}

	> h3 {
		width: 64px;
		height: 32px;
		background: #18a05e;
		border-radius: 3px;
		margin: 0 30px 0 0;
		color: #fff;
		font-size: 14px;
		line-height: 32px;
		font-weight: 100;
		text-align: center;
		cursor: pointer;
	}

	> h4 {
		width: 64px;
		height: 32px;
		border-radius: 3px;
		border: 1px solid rgba(0, 0, 0, 0.1);
		color: #333;
		font-size: 14px;
		line-height: 32px;
		font-weight: 100;
		text-align: center;
		cursor: pointer;
		margin-right: 30px;
	}
}

.zd3-btm {
  background: rgba(255, 255, 255, 1);
  border-radius: 8px;
  border: 1px solid rgba(0, 0, 0, 0.1);
  margin-top: 10px;
  overflow: hidden;
  &-title {
    display: flex;
    align-items: center;
    height: 70px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.1);
    background: #ffffff;
    > p {
      text-align: center;
      font-size: 16px;
      color: #333;
    }
  }
	.el-pagination {
		white-space: nowrap;
		padding: 15px 5px;
		color: #303133;
		font-weight: bold;
	}
  .addDate {
    margin: 20px 32px 10px 32px;
    height: 32px;
    border-radius: 3px;
    text-align: center;
    line-height: 32px;
    font-size: 14px;
    color: #333;
    cursor: pointer;
    border: 1px dashed rgba(0, 0, 0, 0.25);
  }
  .el-button--text {
    margin: 0 3px;
  }
}
.change {
  display: flex;
  flex-wrap: wrap;
  > p {
    width: 50%;
    font-size: 14px;
    display: flex;
    align-items: center;
    color: #333;
    /deep/.el-input__inner {
      width: inherit;
      background: none;
      height: 32px;
      // line-height: 32px;
      color: #333;
      border: 1px solid rgba(0, 0, 0, 0.1);
      padding: 0 25px;
    }
    /deep/.el-input__icon {
      line-height: 32px;
    }
    .userselect {
      // max-width: 250px;
      flex: 1;
    }

    > span {
      display: block;
      width: 120px;
      text-align: right;
      padding-right: 15px;
    }
    > input {
      width: inherit;
      flex: 1;
      height: 32px;
      border-radius: 3px;
      border: 1px solid rgba(0, 0, 0, 0.1);
      padding-left: 10px;
      color: #333;
    }
  }
}
</style>